package com.roc.service.impl;

import java.io.File;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.roc.bean.JsonBean;
import com.roc.dao.DaoException;
import com.roc.dao.IBaseDao;
import com.roc.dao.IMerchantDao;
import com.roc.dao.ISQLBaseDao;
import com.roc.pojo.MerinfoStop;
import com.roc.pojo.Operators;
import com.roc.pojo.TblMchtBankAccount;
import com.roc.pojo.TblMchtBizDeal;
import com.roc.pojo.TblMchtBizFee;
import com.roc.pojo.TblMchtBusiness;
import com.roc.pojo.TblMchtExtendInfo;
import com.roc.pojo.TblMchtInf;
import com.roc.pojo.TblTermInf;
import com.roc.pojo.TblTermInfId;
import com.roc.pojo.TblTermRiskCfg;
import com.roc.pojo.TblTermRiskCfgId;
import com.roc.service.ServiceException;
import com.roc.service.merinfo.MerInfoImportBatchService;
import com.roc.util.CheckIdCard;
import com.roc.util.Constance;
import com.roc.util.DateUtil;
import com.roc.util.constant.ConfigMerinfoUtil;
import com.roc.util.constant.ConfigProperties;
import com.roc.util.constant.MerinfoStatus;
import com.roc.util.constant.Role;
import com.roc.util.constant.SysLogType;

/**
 * 
 * @author ml
 *
 */
@Service
@Transactional(rollbackFor = { ServiceException.class })
public class MerInfoBatchImportServiceImpl implements MerInfoImportBatchService {
	private static Logger log = LogManager
			.getLogger(MerInfoBatchImportServiceImpl.class);

	@Autowired
	private IMerchantDao merchantDao;

	@Autowired
	private ISQLBaseDao sqlBaseDao;
	
	@Autowired
	private IBaseDao baseDao;
	
	@Override
	public synchronized Map<String ,Object> merInfoImportToDB(File upload, Operators oper,String imporNum)
			throws ServiceException {
		log.info("操作员：" + oper.getRealName() + "正在批量导入商户");
		List<List<Object>> trList = new ArrayList<List<Object>>();// 将Excel中数据存入List中
		List<List<Object>> noImportedList = new ArrayList<List<Object>>();// 将Excel中数据存入List中
		Map<String ,Object> resultMap = new HashMap<String, Object>();//保存最终处理结果
		resultMap.put("importedFlag", false);
		int count =0;//成功导入数据库商户计数
		try {
			
			// 1、取出Excel中数据
			boolean formatRegular = excelToList(upload,resultMap,trList,imporNum);
			if(!formatRegular){
				return resultMap;
			}
			log.info("Excel中有数据：【" + trList.size() + "】条");

			// 2、校验Excel中数据
			boolean checkData = checkData(trList,resultMap);
			log.info("基本规则校验完成");
			if(!checkData){
				return resultMap;
			}
			
			// 3、将数据存入DB
			if (trList != null && trList.size() > 0) {//开始
				
				Iterator<List<Object>> it = trList.iterator();
				while (it.hasNext()) {/***************循环List<List<Object>> （符合基本校验规则的数据） 开始****************/
					List<Object> obj = it.next();
					
					//校验商户号是否已存在
					String merinfoNo = Constance.Null2EmptyTrim(obj.get(MCHT_CD_IND));
					
					String selectMchtCdSql = "select count(1) from tbl_mcht_inf t where t.MCHT_CD=?";
					int mchtCdCount =  Integer.parseInt(String.valueOf(sqlBaseDao.findObj(selectMchtCdSql, new Object[]{merinfoNo})));
					if(mchtCdCount > 0){
						log.info("商户号【"+merinfoNo+"】已被使用");
						throw new ServiceException("商户号【"+merinfoNo+"】已被使用");
					}
					
					
					// 查询所属机构
					String sql = "SELECT T.INS_COMPANY_CD FROM TBL_INS_INF T WHERE T.INS_ID_CD=? AND INS_TYPE=1";
					Object[] params = { Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)) };
					Object parentOrg = sqlBaseDao.findObj(sql, params);
					
					if(parentOrg == null){
						log.info("机构号：【"+Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND))+"】不存在");
						throw new ServiceException("机构号：【"+Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND))+"】不存在");
						
					}
					
					//校验传入的开户行名称能否从银行字典表中查到数据，若查不到则返回
					String banksql ="select code from TBL_UNIONPAY_BANKLIST where name = ?";
					Object[] bankparams = { Constance.Null2EmptyTrim(obj.get(BANK_NAME_IND)) };
					Object bankCode = sqlBaseDao.findObj(banksql, bankparams);
					
					if("".equals(Constance.Null2EmptyTrim(bankCode))){
						log.info("无法根据开户行名称：【"+Constance.Null2EmptyTrim(obj.get(BANK_NAME_IND))+"】查到联行号");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的记录的开户行名称填写错误");
						
					}
					
					/*********************将商户信息保存到商户表正式表     开始*********************/
					
					
					
					//校验商户简称是否已存在
					String nameBusiSql = "select count(1) from TBL_MCHT_INF where name_busi=?";
					Object[] namebusiParams = {Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))};
					Object namebusiRs = sqlBaseDao.findObj(nameBusiSql, namebusiParams);
					
					if(Integer.parseInt(String.valueOf(namebusiRs))>0){
						log.info("商户简称【"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"】已被使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的商户简称已被使用");
						
					}
					
					//校验营业执照号码是否使用超过十次
//					String busiLiceNoSql = "select Count(1) from TBL_MCHT_INF where BUSI_LICE_NO =? AND STATUS<>'02' AND BANK_BELONG_CD=? ";
//					Object[] liceNoParams = {Constance.Null2EmptyTrim(obj.get(5)),Constance.Null2EmptyTrim(obj.get(0))};
//					Object liceNoRs = sqlBaseDao.findObj(busiLiceNoSql, liceNoParams);
					boolean liceNoRs = queryCount("1", Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND)), Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)), oper);
					
					if(!liceNoRs){
						log.info("营业执照【"+Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND))+"】使用次数超过限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的营业执照使用次数超过限制");
						
					}
					
					
					
					//身份证号码次数限制
//					String idCardSql = "select count(1) from TBL_MCHT_INF where CERTIF_NO=? AND STATUS<>'02' and CERTIF_NO<>'310109197712243631' AND BANK_BELONG_CD=? ";
//					Object[] idCardParams = {Constance.Null2EmptyTrim(obj.get(10)),Constance.Null2EmptyTrim(obj.get(0))};
//					Object idCardRs = sqlBaseDao.findObj(idCardSql,idCardParams);
					boolean idCardRs = queryCount("0", Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND)), Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)), oper);
					
					if(!idCardRs){
						log.info("法人代表证件号【"+Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND))+"】使用次数超过限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的法人代表证件号使用次数超过限制");
						
					}
					
					//结算卡号次数限制 2
//					String bankAccountSql = "SELECT COUNT(1) FROM TBL_MCHT_BANKACCOUNT T,TBL_MCHT_INF TI WHERE TI.MCHT_CD=T.OWNER_CD AND T.ACCOUNT=? AND TI.STATUS<>'02' AND BANK_BELONG_CD=? ";
//					Object[] bankAccountParams = {Constance.Null2EmptyTrim(obj.get(25)),Constance.Null2EmptyTrim(obj.get(0))};
//					Object bankAccountRs = sqlBaseDao.findObj(bankAccountSql, bankAccountParams);
					
					boolean bankAccountRs = queryCount("2", Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND)), Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)), oper);
					
					if(!bankAccountRs && !"15000037896588".equals(Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND)))){
						log.info("结算账户账号【"+Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND))+"】使用次数超过限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的结算账户账号使用次数超过限制");
						
					}
					
					//非法人身份证号码次数限制
					if("0".equals(Constance.Null2EmptyTrim(obj.get(ACCOUNT_TYPE_IND))) && "1".equals(Constance.Null2EmptyTrim(obj.get(IS_CERTIF_IND)))){
//						String noCerfSql="SELECT COUNT(1) FROM TBL_MCHT_INF T WHERE  T.STLM_WAY_DESC=? AND T.STATUS<>'02' and T.STLM_WAY_DESC<>'310109197712243631' "
//								+ " AND T.BANK_BELONG_CD=?  ";
//						Object[] nocerfParams = {Constance.Null2EmptyTrim(obj.get(23)),Constance.Null2EmptyTrim(obj.get(0))};
//						Object nocerfRs = sqlBaseDao.findObj(noCerfSql, nocerfParams);
						boolean nocerfRs = queryCount("3", Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND)), Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)), oper); 
						if(!nocerfRs){
							log.info("非法人身份证号【"+Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND))+"】使用次数超过限制，无法使用");
							throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的非法人身份证号使用次数超过限制");
							
						}
					}
					
					//营业执照      Constance.Null2EmptyTrim(obj.get(5))
					boolean liceNoExist = queryExist("1", Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND)), oper);
					if(!liceNoExist){
						log.info("营业执照【"+Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND))+"】被限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的营业执照使用被限制");
						
					}
					
					//身份证号码 Constance.Null2EmptyTrim(obj.get(10))
					boolean certifExist = queryExist("0", Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND)), oper);
					if(!certifExist){
						log.info("法人代表证件号【"+Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND))+"】使用被限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的法人代表证件号被限制");
						
					}
					
					//结算卡号 Constance.Null2EmptyTrim(obj.get(25))
					boolean bankAccountExist = queryExist("2",  Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND)), oper);
					if(!bankAccountExist){
						log.info("结算账户账号【"+Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND))+"】被限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的结算账户账号使用被限制");
						
					}
					
					//非法人身份证号码 Constance.Null2EmptyTrim(obj.get(23))
					boolean notCertifExist = queryExist("3",  Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND)), oper);
					if(!notCertifExist){
						log.info("非法人身份证号【"+Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND))+"】使用被限制，无法使用");
						throw new ServiceException("商户简称为"+Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND))+"的非法人身份证号使用被限制");
						
					}
					
					String mccCd = Constance.Null2EmptyTrim(obj.get(MCC42_IND));// mcc码
					String ucBccd = Constance.Null2EmptyTrim(obj.get(LOCATION_IND));// 装机市/县代码
					// 生成正式商户号
					
					String serial;
					if("".equals(merinfoNo)){
						serial = merchantDao.handleMerchantno("850", ucBccd,
								mccCd);
						merinfoNo = "850" + ucBccd + mccCd + serial;
						log.info("生成的正式商户号为：" + merinfoNo);
					}else{
						serial = merinfoNo.substring(11);
						log.info("导入的正式商户号为：" + merinfoNo);
					}
					
					obj.set(MCHT_CD_IND, merinfoNo);
					log.info("商户【"+merinfoNo+"】是否特殊费率商户【"+obj.get(IS_SPECIAL_FEE_IND)+"】");
					
					
					TblMchtInf merinfo = new TblMchtInf();
					merinfo.setId(merinfoNo);// 正式商户号
					merinfo.setSn(serial);// 商户序列号
					merinfo.setAipBranCd(String.valueOf(parentOrg));// 所属分公司
					merinfo.setOriChnl("0");// 商户来源渠道，"0"主动发展
					merinfo.setOriChnlDesc(String.valueOf(oper.getId()));
					merinfo.setBankBelongCd(Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)));// 所属收单机构
					Date date = obtainSomeLaterTime();
					String applDate = DateUtil.getDate(date, 0,
							"yyyy-MM-dd");
					merinfo.setApplDate(applDate);// 应用时间
					merinfo.setApprDate(date);//进件时间
					merinfo.setName(Constance.Null2EmptyTrim(obj.get(NAME_IND)));// 工商注册名称
					merinfo.setNameBusi(Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND)));// 营业名称
					merinfo.setBusiLiceNo(Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND)));// 营业执照号码
					merinfo.setBusiMain(Constance.Null2EmptyTrim(obj.get(BUSI_MAIN_IND)));// 主营业务
					merinfo.setCertif(Constance.Null2EmptyTrim(obj.get(CERTIF_IND)));// 法人代表
					merinfo.setCertifType(Constance.Null2EmptyTrim(obj.get(CERTIF_TYPE_IND)));// 法人代表证件类型
					merinfo.setCertifNo(Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND)));// 法人证件号码
					merinfo.setNationCd(Constance.Null2EmptyTrim(obj.get(MCHT_TYPE_IND)));// 注册地址国家代码,默认值,现保存商户类型
					merinfo.setProvCd(Constance.Null2EmptyTrim(obj.get(PROV_IND)));// 注册地址省代码
					merinfo.setCityCd(Constance.Null2EmptyTrim(obj.get(CITY_IND)));// 注册地址市代码
					merinfo.setAreaCd(Constance.Null2EmptyTrim(obj.get(AREA_IND)));// 注册地址区县代码
					merinfo.setRegAddr(Constance.Null2EmptyTrim(obj.get(REG_ADDR_IND)));// 注册地址
					merinfo.setContactName(Constance.Null2EmptyTrim(obj.get(CONTACT_PER_IND)));// 商户联系人姓名
					merinfo.setContactPhoneNo(Constance.Null2EmptyTrim(obj
							.get(CONTACT_NO_IND)));// 商户联系人电话
					merinfo.setGroupCD(Constance.Null2EmptyTrim(obj.get(DIRECT_IND)));//商户直间连
					merinfo.setApprovalUserName(Constance.Null2EmptyTrim(obj.get(ACCOUNT_TYPE_IND)));//结算账户类型
					merinfo.setDvpBy(Constance.Null2EmptyTrim(obj.get(IS_CERTIF_IND)));//是否法人结算
					merinfo.setStlmWayDesc(Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND)));//非法人身份证号
					merinfo.setStatus(MerinfoStatus.S_0.getCode());// 正常状态
					merinfo.setBillingLevel(Constance.Null2EmptyTrim(obj.get(SPECIAL_FEE_LEVEL_IND)));
					merinfo.setBillingType(Constance.Null2EmptyTrim(obj.get(SPECIAL_FEE_TYPE_IND)));
					merinfo.setIsGroup("F");
					if (oper.getRoleType().equals(Role.AGENT_BUSS.getCode())) { // 业务员
						merinfo.setExt1(String.valueOf(oper.getSuperiorId()));// 上级id
					} else {
						merinfo.setExt1(String.valueOf(oper.getId()));// 自己
					}
					merinfo.setExt3("1");//0表示平台申请，1表示批量导入
					merinfo.setRecCrtTs(obtainSomeLaterTime());
					merinfo.setOperIn("I");
					merinfo.setRecUpdOpr(String.valueOf(oper.getId()));// 进件人员
					merinfo.setUpMccCd(mccCd);// 商户mcc
					merinfo.setUcBccd("4850"+ucBccd);// 32域
					merinfo.setMcc(mccCd);
					merinfo.setUcBccdArea(oper.getOneagentid());	//进件人所属机构
					
					baseDao.editSave(merinfo);
					/*********************将商户信息保存到商户表正式表     结束*********************/
					
					/** 保存商户信息拓展表数据*/
					
					if(!"".equals(Constance.Null2EmptyTrim(obj.get(CERTIF_VAL_BEGIN_IND)))){
						//商户扩展信息
						String extend_hql="from TblMchtExtendInfo t where t.id=?";
						Object[] param = {merinfoNo};
						TblMchtExtendInfo mchtExtend = (TblMchtExtendInfo)baseDao.createQueryUniqueResult(extend_hql,param );
						if(mchtExtend == null){
							TblMchtExtendInfo tblMchtExtendInfo = new TblMchtExtendInfo();
							tblMchtExtendInfo.setId(merinfoNo);
							tblMchtExtendInfo.setCertifStartDate(Constance.Null2EmptyTrim(obj.get(CERTIF_VAL_BEGIN_IND)));
							tblMchtExtendInfo.setCertifEndDate(Constance.Null2EmptyTrim(obj.get(CERTIF_VAL_END_IND)));
							baseDao.editSave(tblMchtExtendInfo);
						}else{
							log.info("商户信息拓展表中，商户【"+merinfoNo+"】已存在");
							throw new ServiceException("商户信息拓展表中，商户【"+merinfoNo+"】已存在");
						}
					}
					
					long a=merchantDao.addMerinfoAgentRelations(merinfoNo,merinfo.getNameBusi(),Long.parseLong(merinfo.getRecUpdOpr()));//调用存储过程添加代理商、商户关系表
					if(a>0){
						log.info("添加【"+a+"】条代理商商户关系记录成功！");
					}
					/*********************终端相关信息保存   开始******************************/
					StringBuffer termMsgSb = new StringBuffer("");
					for(int i=0;i<Integer.parseInt(Constance.Null2EmptyTrim(obj.get(OPEN_TERM_IND)));i++){
						//将信息插入终端表开始
						String termsql="SELECT SEQ_DEVICE_CD.nextval CURRENTS FROM dual ";
						Object currentSeq=sqlBaseDao.findObj(termsql, null);
						
						String termMsg = Constance.Null2EmptyTrim(obj.get(ALL_COLUMN+i));
						String[] termArray = termMsg.split(",");
						String insLoc = "";//装机地址
						String termId = new DecimalFormat("00000000").format(i+1);//终端号
						String termBand = "";//终端品牌
						String termType = "";//终端类型
						String sn = "YJ"+String.valueOf(currentSeq);//sn
						
						if(termArray.length == 1){
							insLoc = Constance.Null2EmptyTrim(termArray[0]);
						}else if(termArray.length == 2){
							
							termId = Constance.Null2EmptyTrim(termArray[0]);
							insLoc = Constance.Null2EmptyTrim(termArray[1]);
							
						}else{
							
							termId = Constance.Null2EmptyTrim(termArray[0]);
							sn = Constance.Null2EmptyTrim(termArray[1]);
							termBand = Constance.Null2EmptyTrim(termArray[2]);
							termType = Constance.Null2EmptyTrim(termArray[3]);
							insLoc = Constance.Null2EmptyTrim(termArray[4]);
							
							String selectSnCount = "select count(1) from TBL_TERM_INF t where t.TMNL_BRAND=? and t.DEVICE_CD=?";
							int snCount = Integer.parseInt(String.valueOf(sqlBaseDao.findObj(selectSnCount, new Object[]{termBand,sn})));
							if(snCount>0){
								log.info("商户号【"+merinfoNo+"】，终端号【"+termId+"】，品牌【"+termBand+"】，SN【"+sn+"】已存在");
								throw new ServiceException("商户号【"+merinfoNo+"】，终端号【"+termId+"】，品牌【"+termBand+"】，SN【"+sn+"】已存在");
							}
							
						}
						
						//查询终端数量
						String selectTermCount = "select count(1) from TBL_TERM_INF t where t.MCHT_CD=? and t.TERM_ID =?";
						int termCount = Integer.parseInt(String.valueOf(sqlBaseDao.findObj(selectTermCount, new Object[]{merinfoNo,termId})));
						if(termCount>0){
							log.info("商户号【"+merinfoNo+"】，终端号【"+termId+"】已存在");
							throw new ServiceException("商户号【"+merinfoNo+"】，终端号【"+termId+"】已存在");
						}
						
						TblTermInf  terminfo=new TblTermInf();
						TblTermInfId terminfoId=new TblTermInfId();
						
						terminfoId.setMchtCd(merinfoNo);
						terminfoId.setTermId(termId);
						terminfo.setId(terminfoId);
						terminfo.setStatus("01");//初始状态
						terminfo.setTermTp("3");//移动的
						terminfo.setBelong("1");//POS产权方
						terminfo.setBelongSub(Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND)));//产权机构代码
						terminfo.setTmnlMoneyIntype("1");//押金收取方式 0按照商户 1按照终端
						terminfo.setTmnlMoney(0);//押金  0
						terminfo.setInstalllocation(insLoc);
						terminfo.setTmnlIntype("0");//业务受理接入方式：0 无线 1 有线
						terminfo.setDeviceCd(sn);//终端序列号
						terminfo.setRecOprId("I");//操作标识
						terminfo.setRecCrtTs(obtainSomeLaterTime());//记录时间
						terminfo.setRecUpdOpr(String.valueOf(oper.getId()));
						terminfo.setDialOut("60000");//终端呼出号码，默认暂定无用处
						terminfo.setTmnlBrand(termBand);
						terminfo.setTmnlModelNo(termType);
						baseDao.editSave(terminfo);
						log.info("---正式终端表添加商户["+merinfoNo+"]的终端["+terminfo.getId().getTermId()+"]成功---");
						//将信息插入终端表结束
						
						termMsgSb.append(terminfo.getId().getTermId()).append(",")
						.append(terminfo.getDeviceCd()).append(",").append(terminfo.getTmnlBrand())
						.append(",").append(terminfo.getTmnlModelNo()).append(",")
						.append(terminfo.getInstalllocation()).append("|");
						
						//保存终端风控信息开始
						//贷记卡
						TblTermRiskCfg risk= new TblTermRiskCfg();
						TblTermRiskCfgId riskId=new TblTermRiskCfgId();
						riskId.setMchtCd( merinfoNo);//商户号
						riskId.setTermId(termId);//终端号
						riskId.setCardType("00");//卡类型  借记卡01、贷记卡 00风控规则
						risk.setId(riskId);
						
						risk.setTotalLimitmoney(1000000);//累计限额
						risk.setAccpetStartTime(Constance.Null2EmptyTrim(obj.get(START_TM_IND)));//营业开始时间
						risk.setAccpetEndTime(Constance.Null2EmptyTrim(obj.get(END_TIME_IND)));//营业结束时间
						//只开通T1
						if(!"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND))) && "".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND)))){
							risk.setSingleLimitmoney(100000);//单笔限额
							risk.setSingleMinMoney(1);//单笔限额下限
						}
						
						//同时开通T1和T0
						if(!"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND))) && !"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND)))){
							risk.setSingleLimitmoney(50000);//单笔限额
							risk.setSingleMinMoney(1);//单笔限额下限
						}
						
						risk.setControlWay("1,2");//控制方式
						risk.setTotalPeriod("1");//累计周期
						risk.setRecCrtTs(obtainSomeLaterTime());//记录时间
						risk.setRecOprId("I");//操作标识
						risk.setOperIn("I");
						risk.setRecUpdOpr(String.valueOf(oper.getId()));//更新柜员
						baseDao.editSave(risk);
						log.info("-----正式风控表添加商户["+merinfoNo+"]的终端["+risk.getId().getTermId()+"]的贷记卡风控信息成功-----");
						
						//借记卡
						TblTermRiskCfg risk1= new TblTermRiskCfg();
						TblTermRiskCfgId riskId1=new TblTermRiskCfgId();
						riskId1.setMchtCd( merinfoNo);//商户号
						riskId1.setTermId(termId);//终端号
						riskId1.setCardType("01");//卡类型  借记卡01、贷记卡 00风控规则
						risk1.setId(riskId1);
						
						risk1.setTotalLimitmoney(1000000);//累计限额
						risk1.setAccpetStartTime(Constance.Null2EmptyTrim(obj.get(START_TM_IND)));//营业开始时间
						risk1.setAccpetEndTime(Constance.Null2EmptyTrim(obj.get(END_TIME_IND)));//营业结束时间
						//只开通T1
						if(!"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND))) && "".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND)))){
							risk1.setSingleLimitmoney(100000);//单笔限额
							risk1.setSingleMinMoney(1);//单笔限额下限
						}
						
						//同时开通T1和T0
						if(!"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND))) && !"".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND)))){
							risk1.setSingleLimitmoney(50000);//单笔限额
							risk1.setSingleMinMoney(1);//单笔限额下限
						}
						
						risk1.setControlWay("1,2");//控制方式
						risk1.setTotalPeriod("1");//累计周期
						risk1.setRecCrtTs(obtainSomeLaterTime());//记录时间
						risk1.setRecOprId("I");//操作标识
						risk1.setOperIn("I");
						risk1.setRecUpdOpr(String.valueOf(oper.getId()));//更新柜员
						baseDao.editSave(risk1);
						log.info("-----正式风控表添加商户["+merinfoNo+"]的终端["+risk1.getId().getTermId()+"]的借记卡风控信息成功-----");
						//保存终端风控信息结束
					}
					
					obj.set(ALL_COLUMN, termMsgSb.toString().substring(0, termMsgSb.toString().length()-1));
					/*********************终端相关信息保存   结束******************************/
					
					/*********************保存结算账户信息   开始********************************/
					TblMchtBankAccount bankAccount=new TblMchtBankAccount();
					bankAccount.setOwnerCd(merinfoNo);//商户号
					bankAccount.setAccountType("01"); //账户类型  **********************************
					bankAccount.setRecCrtTs(obtainSomeLaterTime());//记录时间
					bankAccount.setUcBccd(String.valueOf(bankCode).substring(0,3));//联行号前三位
					bankAccount.setBankCode(String.valueOf(bankCode));//开户行支付系统联行号
					bankAccount.setBankName(Constance.Null2EmptyTrim(obj.get(BANK_NAME_IND)));//开户行名称
					bankAccount.setName(Constance.Null2EmptyTrim(obj.get(ACCOUNT_NAME_IND)));
					bankAccount.setAccount(Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND)));
					bankAccount.setOperIn("I");
					bankAccount.setRecUpdOpr(String.valueOf(oper.getId()));
					baseDao.editSave(bankAccount);
					log.info("----添加商户["+merinfoNo+"]结算账户正式表成功------");
					/*********************保存结算账户信息   结束********************************/
					
					/*********************添加业务受理及服务信息    开始*******************************/
					TblMchtBusiness  tmbusiness = new TblMchtBusiness();
					tmbusiness.setMchtCd(merinfoNo);//商户号
					tmbusiness.setFeeMoneyCd("RMB");
					tmbusiness.setFeeModeType("0");
					tmbusiness.setFeeHoliday("0");
					tmbusiness.setServiceFeeStart(Constance.formateDate1());
					tmbusiness.setServiceFeeYesno("0");
					tmbusiness.setRecUpdOpr(String.valueOf(oper.getId()));
					tmbusiness.setRecCrtTs(obtainSomeLaterTime());
					tmbusiness.setOperIn("I");
					baseDao.editSave(tmbusiness);
					log.info("----添加商户["+merinfoNo+"]业务受理正式表成功------");
					/*********************添加业务受理及服务信息    结束*******************************/
					
					
					if("1000".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND)))){/*******************产品开通相关信息保存    开始*******************/
						List<String> transCdList = new ArrayList<String>();
						
						transCdList.add("1011");//消费
						
						if("1001".equals(Constance.Null2EmptyTrim(obj.get(BALANCE_QUERY_IND)))){
							transCdList.add("1001");//余额查询
						}
						
						
						if("2011".equals(Constance.Null2EmptyTrim(obj.get(REVERSE_IND)))){
							transCdList.add("2011");//消费撤销
						}
						
						if("4011".equals(Constance.Null2EmptyTrim(obj.get(CZ_IND)))){
							transCdList.add("4011");//消费冲正
						}
						
						
						for(String transStr:transCdList){
							//添加产品信息开始
							TblMchtBizDeal tmb=new TblMchtBizDeal();
							tmb.setMchtCd(merinfoNo);
	 
							tmb.setProdCd(ConfigMerinfoUtil.T1_FUNCTION);
							tmb.setBizCd(ConfigMerinfoUtil.T1_BIZ_CD);
							tmb.setTransCd(transStr);//
							tmb.setOperIn("I");
							tmb.setRecUpdOpr(String.valueOf(oper.getId()));
							tmb.setRecCrtTs(obtainSomeLaterTime());
							baseDao.editSave(tmb);
							log.info("-----添加商户["+merinfoNo+"]T1产品信息[prodcd-->"+tmb.getProdCd()+"][transcd-->"+tmb.getTransCd()+"]成功");
							
						}
						log.info("T1产品信息保存成功");
						
						//添加T1手续费开始
						
						
						List<String> subBizCdList1 =  new ArrayList<String>();//子业务码集合
						subBizCdList1.add("0001000");//T1借记卡
						subBizCdList1.add("0001001");//T1贷记卡
						for(String su:subBizCdList1){
							TblMchtBizFee  teb=new TblMchtBizFee();
							teb.setMchtCd(merinfoNo);//商户号
							teb.setProdCd(ConfigMerinfoUtil.T1_FUNCTION);//产品  业务类型
							teb.setBizCd(ConfigMerinfoUtil.T1_BIZ_CD);
							teb.setSubBizCd(su);
							if("0001000".equals(su)){
								teb.setMchtFeePercent(new BigDecimal(Constance.Null2EmptyTrim(obj.get(T1_JIE_FEE_IND))).doubleValue());//24
								teb.setMchtFeePctMax(new BigDecimal(Constance.Null2EmptyTrim(obj.get(T1_JIE_MAX_IND))).doubleValue());//用作现金封顶
							}
							if("0001001".equals(su)){
								teb.setMchtFeePercent(new BigDecimal(Constance.Null2EmptyTrim(obj.get(T1_DAI_FEE_IND))).doubleValue());//26
								teb.setMchtFeePctMax(0d);//用作现金封顶
							}
							teb.setMchtFeeMd("0"); ///未知参数不能为空
							teb.setMchtAFeeSame("0"); ///未知参数不能为空
							teb.setMchtAFeeMd("0"); ///未知参数不能为空
							teb.setOperIn("I");
							teb.setRecUpdOpr(String.valueOf(oper.getId()));
							teb.setRecCrtTs(obtainSomeLaterTime());
							baseDao.editSave(teb);
						}
						log.info("==========T1费率保存成功============");
						
						
						//添加T1手续费结束
						
						if("1171".equals(Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND)))){//开通T0
							TblMchtBizDeal tmb0=new TblMchtBizDeal();
							tmb0.setMchtCd(merinfoNo);
							tmb0.setProdCd(ConfigMerinfoUtil.T0_FUNCTION);
							tmb0.setBizCd(ConfigMerinfoUtil.T0_BIZ_CD);
							tmb0.setTransCd("1171");
							tmb0.setOperIn("I");
							tmb0.setRecUpdOpr(String.valueOf(oper.getId()));
							tmb0.setRecCrtTs(obtainSomeLaterTime());
							baseDao.editSave(tmb0);
							log.info("T0产品信息保存成功");
							
							List<String> subBizCdList0 = new ArrayList<String>();//T0子业务码集合
							subBizCdList0.add("0002000");//T0借记卡
							subBizCdList0.add("0002001");//T0贷记卡
							subBizCdList0.add("0002004");//已没有，手续费给0
							subBizCdList0.add("0002005");//已没有，手续费给0
							for(String su0:subBizCdList0){
								TblMchtBizFee  teb=new TblMchtBizFee();
								teb.setMchtCd(merinfoNo);//商户号
								teb.setProdCd(ConfigMerinfoUtil.T0_FUNCTION);//产品  业务类型
								teb.setBizCd(ConfigMerinfoUtil.T0_BIZ_CD);
								teb.setSubBizCd(su0);
								if("0002000".equals(su0)){//T0借记卡
									teb.setMchtFeePercent(new BigDecimal(Constance.Null2EmptyTrim(obj.get(T0_JIE_FEE_IND))).doubleValue());//26
									teb.setMchtFeePctMax(0d);//用作现金封顶
								}
								if("0002001".equals(su0)){//T0贷记卡
									teb.setMchtFeePercent(new BigDecimal(Constance.Null2EmptyTrim(obj.get(T0_DAI_FEE_IND))).doubleValue());//27
									teb.setMchtFeePctMax(0d);//用作现金封顶
								}
								
								if("0002004".equals(su0)||"0002005".equals(su0)){
									teb.setMchtFeePercent(0d);//
									teb.setMchtFeePctMax(0d);//用作现金封顶
								}
								teb.setMchtFeeMd("0"); ///未知参数不能为空
								teb.setMchtAFeeSame("0"); ///未知参数不能为空
								teb.setMchtAFeeMd("0"); ///未知参数不能为空
								teb.setOperIn("I");
								teb.setRecUpdOpr(String.valueOf(oper.getId()));
								teb.setRecCrtTs(obtainSomeLaterTime());
								baseDao.editSave(teb);
							}
							log.info("T0手续费保存成功");
						}
						
					}/*******************产品开通相关信息保存    结束*******************/
					
					
					count ++;
					merchantDao.addSyslog(SysLogType.MERCHANT_BATCHER_IMPORT.getCode(),
							SysLogType.MERCHANT_BATCHER_IMPORT.getName(),
							oper.getAccountNo(), 
							"操作员【" + oper.getAccountNo()+ "】，批量导入商户【" + merinfo.getId() + "】成功");
					
					noImportedList.add(obj);
				}/***************循环List<List<Object>> （大部分符合校验的数据） 结束****************/
				
				
			}//结束
		} catch (Exception e) {
			log.error("批量导入数据异常：" + e.getMessage());
			throw new ServiceException(e);
		}
		log.info("成功导入数据：【"+count+"】条");
		resultMap.put("msg", "成功导入数据：【"+count+"】条");
		resultMap.put("importedFlag", true);
		resultMap.put("noImportedList", noImportedList);
		return resultMap;

	}
	
	/**
	 * 
	 * @param type 0 身份证 1营业执照 2结算卡 3非法人身份证
	 * @param obj 号码
	 * @param op 操作员
	 * @return
	 * @throws ServiceException
	 */
	public boolean queryExist(String type,String obj,Operators op) throws ServiceException {
		String sql="";
		sql=" SELECT COUNT(1) FROM T_MERINFO_STOP T WHERE  T.mid=? AND T.mid<>'310109197712243631' ";
		String name="";
		if(type.equals("0")){//身份证
			//sql="SELECT COUNT(1) FROM T_MERINFO_STOP T WHERE  T.mid=? AND STATUS='0' ";
			name="身份证";
		}else if(type.equals("1")){//营业执照
			//sql="SELECT COUNT(1) FROM T_MERINFO_STOP T WHERE  T.mid=? AND STATUS='1' ";
			name="营业执照";
		}else if(type.equals("2")){//结算卡
			//sql="SELECT COUNT(1) FROM T_MERINFO_STOP T WHERE  T.mid=? AND STATUS='2' ";
			name="结算卡号";
		}else if(type.equals("3")){//非法人身份证
			name="非法人身份证";
		}
		try {
			log.info("----审核查询身份证、营业执照、结算卡号、非法人身份证 是否被限制类型["+type+"]参数["+obj+"]---");
			Object[] params={obj.trim()};
			Object r = sqlBaseDao.findObj(sql, params);
			long count = Long.parseLong(r.toString());
			sql =" SELECT COUNT(1) FROM TBL_WHITE T WHERE T.STATUS='1' AND T.ACCOUNTNO=? ";
			Object[] accountNo = {op.getAccountNo()};
			Object ra = sqlBaseDao.findObj(sql, accountNo);
			long acount = Long.parseLong(ra.toString());
			if(acount<1 && count>0){
				return false;//被限制
			} 
		} catch (DaoException e) {
			log.error("-------审核查询商户结算卡、营业执照、法人身份证、非法人身份证是否被风控出错-----",e);
			throw new ServiceException("-------审核查询商户结算卡、营业执照、法人身份证、非法人身份证是否被风控出错-----",e);
			
		}
		return true;
	}
	
	/**
	 * 根据类别查询在系统已存在多少数量
	 * @param  type 类型  0-身份证   1-营业执照   2-结算卡 3-非法人身份证
	 * */
	public boolean queryCount(String type,String obj,String bankBelongCode,Operators op) throws ServiceException {
		JsonBean jb= new JsonBean();
		String sql="";
		String name="";
		if(type.equals("0")){//身份证
			sql="select count(1) from TBL_MCHT_INF where CERTIF_NO=? AND STATUS<>'02' and CERTIF_NO<>'310109197712243631' AND BANK_BELONG_CD=? ";
			name="身份证";
		}else if(type.equals("1")){//营业执照
			sql="select Count(1) from TBL_MCHT_INF where BUSI_LICE_NO =? AND STATUS<>'02' AND BANK_BELONG_CD=? "; 
			name="营业执照";
		}else if(type.equals("2")){//结算卡
			sql="SELECT COUNT(1) FROM TBL_MCHT_BANKACCOUNT T,TBL_MCHT_INF TI WHERE TI.MCHT_CD=T.OWNER_CD AND T.ACCOUNT=? AND TI.STATUS<>'02' AND BANK_BELONG_CD=? ";
			name="结算卡号";
		}else if(type.equals("3")){//非法人身份证
			sql="SELECT COUNT(1) FROM TBL_MCHT_INF T WHERE  T.STLM_WAY_DESC=? AND T.STATUS<>'02' and T.STLM_WAY_DESC<>'310109197712243631' "
					+ " AND T.BANK_BELONG_CD=?  ";
			name="非法人身份证";
		}
		try {
			log.info("----审核查询身份证、营业执照、结算卡号类型、非法人身份证 ["+type+"]参数["+obj+"]---");
			Object[] params={obj.trim(),bankBelongCode};
			Object r = sqlBaseDao.findObj(sql, params);
			long count = Long.parseLong(r.toString());
			/************************************--------检测整改---------******************************************/
			sql =" SELECT COUNT(1) FROM TBL_WHITE T WHERE T.STATUS='1' AND T.ACCOUNTNO=? ";
			Object[] accountNo = {op.getAccountNo()};
			Object ra = sqlBaseDao.findObj(sql, accountNo);
			long acount = Long.parseLong(ra.toString());
			if(acount<1 && ((type.equals("0") &&  count>2) || (type.equals("1") &&  count>2) 
			 || (type.equals("2") &&  count>1)  || (type.equals("3") &&  count>1))){//身份证
				MerinfoStop stop = new MerinfoStop();
				sql="select COUNT(1) from t_merinfo_stop where mid=? ";
				Object[] par={obj.trim()};
				Object s = sqlBaseDao.findObj(sql, par);
				long countNo = Long.parseLong(s.toString());
				if(countNo<1){
					stop.setDetail(name+"在系统中已录入["+count+"]次，请警惕！");  //原因
					if( op.getId()==0){
						stop.setAgentId(40002L);              //添加人员id
					}else{
						stop.setAgentId(op.getId());
					}
					if(null==op.getRealName()){
						stop.setAgentName("cj");
					}else{
						stop.setAgentName(op.getRealName());      //添加人员姓名
					}
					stop.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(obtainSomeLaterTime()));  //时间
					stop.setStatus(type);  //类型
					stop.setMid(obj.trim());       //对应号码
					baseDao.editSave(stop);
				}
				return false;
				
			}else{
				return true;
			} 
			
		} catch (DaoException e) {
			log.error("-------审核查询商户结算卡、营业执照、法人身份证出错、非法人身份证-----",e);
			throw new ServiceException("-------审核查询商户结算卡、营业执照、法人身份证出错、非法人身份证-----",e);
		}
	}

	/**
	 * jiangExcel中的数据转存入List对象中
	 * 
	 * @param upload
	 *            上传的文件
	 * @param trList
	 *            存储Excel中数据的List对象
	 * @return
	 */
	public boolean excelToList(File upload,Map<String ,Object> resultMap, List<List<Object>> trList,String imporNum) {

		try {
			// 构造 XSSFWorkbook 对象，strPath 传入文件路径
			XSSFWorkbook xwb = new XSSFWorkbook(upload.getPath());
			// 得到Excel工作表对象
			XSSFSheet sheet = xwb.getSheetAt(0);
			// 得到行数
			int trLength = sheet.getPhysicalNumberOfRows();
			log.info("Excel中记录的总行数是：" + (trLength - 1));
			
			// 每条记录列数
			Row row = sheet.getRow(0);
			int tdLength = row.getPhysicalNumberOfCells();
			log.info("每条记录的列数："+tdLength);
			Row modelTitle = sheet.getRow(0);
			String[] modelTitleArray = { "机构号", "商户号", "装机地址市/县", "MCC42域",
					"商户工商注册名称", "营业名称", "营业执照号码", "经营范围", "主营业务", "法人代表",
					"法人证件类型", "法人代表证件号", "身份证有效起始日期","身份证有效结束日期", "商户联系人", "商户联系人电话",
					"营业起始时间", "营业终止时间", "商户注册地址省地址", "商户注册地址地市地址",
					"商户注册地址区县地址", "商户注册地址", "商户类型", "商户直间连", "特殊计费类型",
					"特殊计费档次", "结算账户类型", "是否法人结算", "非法人身份证号", "结算账户名称",
					"结算账户账号", "结算账户开户行名称", "是否特殊费率商户", "开通T1", "T1借记卡费率(%)",
					"T1借记卡封顶", "T1贷记卡费率(%)", "开通T0", "T0借记卡费率(%)",
					"T0贷记卡费率(%)", "余额查询", "消费撤销","消费冲正", "开通终端数量" };
			boolean modelTitleFlag = false;
			for(int i =0;i<ALL_COLUMN;i++){
				Cell modelTitleCell  = modelTitle.getCell(i);
				modelTitleCell.setCellType(Cell.CELL_TYPE_STRING);
				if(!modelTitleArray[i].equals(modelTitleCell.getStringCellValue())){
					log.info("列名【"+modelTitleCell.getStringCellValue()+"】错误");
					modelTitleFlag = true;
					break;
				}
			}
			if(modelTitleFlag){
				resultMap.put("msg", "Excel列名错误");
				return false;
			}
			
			int imMerNum = Integer.parseInt(imporNum);
			if(imMerNum != (trLength - 1)){
				resultMap.put("msg", "导入总数填写错误");
				return false;
			}
			for (int i = 1; i < trLength; i++) {
				List<Object> tdList = new ArrayList<Object>();
				Row r = sheet.getRow(i);
				
				for (int j = 0; j < tdLength; j++) {
					Cell c = r.getCell(j);
					/*
					 * 将所有列的内容都设置成String类型，否则会出Excel异常： Cannot get a text value
					 * from a numeric cell
					 */
					if (c != null) {
						c.setCellType(Cell.CELL_TYPE_STRING);
						tdList.add(c.getStringCellValue());
					}else{
						tdList.add("");
					}
					
				}

				trList.add(tdList);
			}
			
		} catch (Exception e) {
			resultMap.put("msg", "Excel解析异常,请检查是否存在空白行");
			log.error("将Excel中数据封装到List容器中异常：" + e.getMessage());
//			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	
	  //该需求变化过于频繁，将模板对应字段下标以常量管理，便于应对多变的需求
	/**机构号*/
	private static final int INS_ID_CD_IND = 0;
	/**商户号*/
	private static final int MCHT_CD_IND = 1;
	/**装机地址市/县*/
	private static final int LOCATION_IND = 2;
	/**MCC42域*/
	private static final int MCC42_IND = 3;
	/**商户工商注册名称*/
	private static final int NAME_IND = 4;
	/**营业名称*/
	private static final int NAME_BUSI_IND = 5;
	/**营业执照号码*/
	private static final int BUSI_LICE_IND = 6;
	/**经营范围*/
	private static final int BUSI_RANGE_IND = 7;
	/**主营业务*/
	private static final int BUSI_MAIN_IND = 8;
	/**法人代表*/
	private static final int CERTIF_IND = 9;
	/**法人证件类型*/
	private static final int CERTIF_TYPE_IND = 10;
	/**法人代表证件号*/
	private static final int CERTIF_NO_IND = 11;
	/**身份证有效起始日期*/
	private static final int CERTIF_VAL_BEGIN_IND = 12;
	/**身份证有效结束日期*/
	private static final int CERTIF_VAL_END_IND = 13;
	/**商户联系人*/
	private static final int CONTACT_PER_IND = 14;
	/**商户联系人电话*/
	private static final int CONTACT_NO_IND = 15; 
	/**营业起始时间*/
	private static final int START_TM_IND = 16;
	/**营业终止时间*/
	private static final int END_TIME_IND = 17;
	/**商户注册地址省地址*/
	private static final int PROV_IND = 18;
	/**商户注册地址地市地址*/
	private static final int CITY_IND = 19;
	/**商户注册地址区县地址*/
	private static final int AREA_IND = 20;
	/**商户注册地址*/
	private static final int REG_ADDR_IND = 21;
	/**商户类型*/
	private static final int MCHT_TYPE_IND = 22;
	/**商户直间连*/
	private static final int DIRECT_IND = 23; 
	/**特殊计费类型*/
	private static final int SPECIAL_FEE_TYPE_IND = 24;
	/**特殊计费档次*/
	private static final int SPECIAL_FEE_LEVEL_IND = 25;
	/**结算账户类型  ( 保存是否对公账户1、或对私账户0)*/
	private static final int ACCOUNT_TYPE_IND = 26;
	/**是否法人结算 （ 0是  1否法人结算账户，若为否则需要非法人身份证号）*/
	private static final int IS_CERTIF_IND = 27;
	/**非法人身份证号*/
	private static final int NO_CERTIF_IND = 28; 
	/**结算账户名称*/
	private static final int ACCOUNT_NAME_IND = 29;
	/**结算账户账号*/
	private static final int ACCOUNT_IND = 30; 
	/**结算账户开户行名称*/
	private static final int BANK_NAME_IND = 31; 
	/**是否特殊费率商户*/
	private static final int IS_SPECIAL_FEE_IND = 32;
	/**开通T1*/
	private static final int OPEN_T1_IND = 33; 
	/**T1借记卡费率(%)*/
	private static final int T1_JIE_FEE_IND = 34;
	/**T1借记卡封顶*/
	private static final int T1_JIE_MAX_IND = 35;
	/**T1贷记卡费率(%)*/
	private static final int T1_DAI_FEE_IND = 36;
	/**开通T0*/
	private static final int OPEN_T0_IND = 37;
	/**T0借记卡费率(%)*/
	private static final int T0_JIE_FEE_IND = 38;
	/**T0贷记卡费率(%)*/
	private static final int T0_DAI_FEE_IND = 39;
	/**余额查询*/
	private static final int BALANCE_QUERY_IND = 40;
	/**消费撤销*/
	private static final int REVERSE_IND = 41;
	/**冲正*/
	private static final int CZ_IND = 42;
	/**开通终端数量*/
	private static final int OPEN_TERM_IND = 43;
	
	/**Excel不变列总列数*/
	private static final int ALL_COLUMN=44;

	/**
	 * 数据校验
	 * @param dataList 全部的数据
	 * @param noImportList 没有成功导入Excel的数据
	 */
	public boolean checkData(List<List<Object>> dataList,
			Map<String ,Object> resultMap) {
		try {
			if (dataList != null && dataList.size() > 0) {
				Iterator<List<Object>> it = dataList.iterator();
				int checkDataCount = 1;
				while (it.hasNext()) {
					
					List<Object> obj = it.next();
					if (obj != null && obj.size() > ALL_COLUMN) {//判断每一条记录的规则  开始
						
						//机构号 0
						String insIdCd = Constance.Null2EmptyTrim(obj.get(INS_ID_CD_IND));
						if("".equals(insIdCd)){
							resultMap.put("msg", "第"+checkDataCount+"行机构号为空");
							return false;
						}
						
						//商户号1
						String mchtCd = Constance.Null2EmptyTrim(obj.get(MCHT_CD_IND));
						
						//装机地址市/县校验
						String cityAreaName = Constance.Null2EmptyTrim(obj.get(LOCATION_IND));
						if("".equals(cityAreaName)){
							resultMap.put("msg", "第"+checkDataCount+"行装机地址市/县列为空");
							return false;
						}
						
						//匹配银联市/县
						Map<String,String> unionareaMap = ConfigProperties.getUNCityAreaMap();
						boolean cityAreaNameFlag = transCodeByName(unionareaMap, cityAreaName, LOCATION_IND, obj);
						if(!cityAreaNameFlag){
							resultMap.put("msg","第"+checkDataCount+"行市或者县名称填写错误");
							return false;
						}
						
						//MCC42域
						String mcc42 = Constance.Null2EmptyTrim(obj.get(MCC42_IND));
						if("".equals(mcc42)){
							resultMap.put("msg", "第"+checkDataCount+"行MCC42域值为空");
							return false;
						}
						//匹配MCC42域值
						boolean mcc42Flag = false;
						Map<String,String> mccMap = ConfigProperties.getHyMccTypeProperties();
						for(Entry<String,String> mccEn :mccMap.entrySet()){
							if(mcc42.equals(mccEn.getKey())){
								mcc42Flag = true;
								break;
							}
						}
						if(!mcc42Flag){
							resultMap.put("msg", "第"+checkDataCount+"行MCC42域值填写错误");
							return false;
						}
						
						if (!"".equals(mchtCd)
								&& (mchtCd.length() != 15
										|| !mchtCd.substring(3, 7).equals(
												String.valueOf(obj
														.get(LOCATION_IND))) || !mchtCd
										.substring(7, 11).equals(
												String.valueOf(obj
														.get(MCC42_IND))))) {
							resultMap.put("msg", "第" + checkDataCount
									+ "行商户号值填写错误");
							return false;
						}
						
						//商户工商注册名称
						String fullName = Constance.Null2EmptyTrim(obj.get(NAME_IND));
						if("".equals(fullName)){
							resultMap.put("msg", "第"+checkDataCount+"行商户工商注册名称为空");
							return false;
						}
						
						if(fullName.length()>50){
							resultMap.put("msg", "第"+checkDataCount+"行商户工商注册名称长度过长");
							return false;
						}
						
						//营业名称
						String nameBusi = Constance.Null2EmptyTrim(obj.get(NAME_BUSI_IND));
						if("".equals(nameBusi)){
							resultMap.put("msg", "第"+checkDataCount+"行营业名称为空");
							return false;
						}

						if(nameBusi.length()>50){
							resultMap.put("msg", "第"+checkDataCount+"行营业名称长度过长");
							return false;
						}
						
						//营业执照号码
						String linceNo = Constance.Null2EmptyTrim(obj.get(BUSI_LICE_IND));
						if("".equals(linceNo)){
							resultMap.put("msg", "第"+checkDataCount+"行营业执照号码为空");
							return false;
						}
						
						if(linceNo.length()>50){
							resultMap.put("msg", "第"+checkDataCount+"行营业执照号码长度过长");
							return false;
						}
						
						//经营范围
						/*String busiRange = Constance.Null2EmptyTrim(obj.get(BUSI_RANGE_IND));
						if("".equals(busiRange)){
							resultMap.put("msg", "第"+checkDataCount+"行经营范围为空");
							return false;
						}
						
						if(busiRange.length()>7){
							resultMap.put("msg", "第"+checkDataCount+"行经营范围长度过长");
							return false;
						}*/
						
						//主营业务
						String mainBusi = Constance.Null2EmptyTrim(obj.get(BUSI_MAIN_IND));
						if("".equals(mainBusi)){
							resultMap.put("msg", "第"+checkDataCount+"行主营业务为空");
							return false;
						}
						
						if(mainBusi.length()>16){
							resultMap.put("msg", "第"+checkDataCount+"行主营业务长度过长");
							return false;
						}
						
						//法人代表
						String certif = Constance.Null2EmptyTrim(obj.get(CERTIF_IND));
						if("".equals(certif)){
							resultMap.put("msg", "第"+checkDataCount+"行法人代表为空");
							return false;
						}
						
						if(certif.length()>16){
							resultMap.put("msg", "第"+checkDataCount+"行法人代表长度过长");
							return false;
						}
						
						Map<String,String> certifTypeMap = ConfigProperties.getSysDB1("CERTIF_TYPE",true);
						//法人证件类型
						String certifType = Constance.Null2EmptyTrim(obj.get(CERTIF_TYPE_IND));
						boolean certifTypeFlag = false;
						for(Entry<String, String> en :certifTypeMap.entrySet()){
							if(certifType.equals(en.getKey())){
								certifTypeFlag = true;
								break;
							}
						}
						if(!certifTypeFlag){
							resultMap.put("msg", "第"+checkDataCount+"行法人证件类型填写错误");
							return false;
						}
						
						//法人代表证件号
						String idCardNo = Constance.Null2EmptyTrim(obj.get(CERTIF_NO_IND));
						if("".equals(idCardNo)){
							resultMap.put("msg", "第"+checkDataCount+"行法人证件号为空");
							return false;
						}
						
						if("01".equals(certifType) && !isIdCard(idCardNo)){
							resultMap.put("msg", "第"+checkDataCount+"行法人证件号格式错误");
							return false;
						}
						
						//身份证有效期,非必填
						String validateTmBe = Constance.Null2EmptyTrim(obj.get(CERTIF_VAL_BEGIN_IND));
						String valiedateTmEd = Constance.Null2EmptyTrim(obj.get(CERTIF_VAL_END_IND));
						
						if ((!"".equals(validateTmBe) ^ !"".equals(valiedateTmEd))
								|| (!"".equals(validateTmBe) && !isRegularTime(
										validateTmBe, "yyyy-MM-dd"))
								|| (!"".equals(valiedateTmEd) && !isRegularTime(
										valiedateTmEd, "yyyy-MM-dd"))) {
							resultMap.put("msg", "第" + checkDataCount
									+ "行身份证有效期填写不规范");
							return false;
						}
						
						//商户联系人姓名
						String contactName = Constance.Null2EmptyTrim(obj.get(CONTACT_PER_IND));
						if("".equals(contactName)){
							resultMap.put("msg", "第"+checkDataCount+"行商户联系人姓名为空");
							return false;
						}
						
						if(contactName.length()>50){
							resultMap.put("msg", "第"+checkDataCount+"行商户联系人姓名长度过长");
							return false;
						}
						
						//商户联系人电话
						String contactPh = Constance.Null2EmptyTrim(obj.get(CONTACT_NO_IND));
						if("".equals(contactPh)){
							resultMap.put("msg", "第"+checkDataCount+"行商户联系人电话为空");
							return false;
						}
						
						if(!isPhNumber(contactPh)){
							resultMap.put("msg", "第"+checkDataCount+"行商户联系人电话格式错误");
							return false;
						}
						
						//营业起始时间和终止时间
						String businessStaTime = Constance.Null2EmptyTrim(obj.get(START_TM_IND));
						String businessEndTime = Constance.Null2EmptyTrim(obj.get(END_TIME_IND));
						if(!isRegularTime(businessStaTime,"HHmm") || !isRegularTime(businessEndTime,"HHmm")){
							resultMap.put("msg", "第"+checkDataCount+"行营业起始时间或终止时间填写错误");
							return false;
						}
						
						//商户注册地址省
						String province = Constance.Null2EmptyTrim(obj.get(PROV_IND));
						if("".equals(province)){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址省为空");
							return false;
						}
						
						Map<String,String> unionProMap = ConfigProperties.getGBProviceProperties();
						boolean proFlag = transCodeByName(unionProMap, province, PROV_IND, obj);
						
						if(!proFlag){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址省填写错误");
							return false;
						}
						
						//商户注册地市
						String city = Constance.Null2EmptyTrim(obj.get(CITY_IND));
						if("".equals(city)){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址市为空");
							return false;
						}
						Map<String,String> cityMap = ConfigProperties.getGBCityProperties(Constance.Null2EmptyTrim(obj.get(PROV_IND)));
						boolean cityFlag = transCodeByName(cityMap,city,CITY_IND,obj);
						if(!cityFlag){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址市填写错误");
							return false;
						}
						
						//商户注册区县
						String area = Constance.Null2EmptyTrim(obj.get(AREA_IND));
						if(!"".equals(area)){
							Map<String,String> areaMap = ConfigProperties.getGBAreaProperties(Constance.Null2EmptyTrim(obj.get(CITY_IND)));
							boolean areaFlag = transCodeByName(areaMap,area,AREA_IND,obj);
							if(!areaFlag){
								resultMap.put("msg", "第"+checkDataCount+"行商户注册地址区县填写错误");
								return false;
							}
						}
						
						//商户注册地址
						String addr = Constance.Null2EmptyTrim(obj.get(REG_ADDR_IND));
						if("".equals(addr)){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址为空");
							return false;
						}
						
						if(addr.length()>33){
							resultMap.put("msg", "第"+checkDataCount+"行商户注册地址长度过大");
							return false;
						}
						
						//商户类型
						String merType = Constance.Null2EmptyTrim(obj.get(MCHT_TYPE_IND));
						if(!"0".equals(merType) && !"1".equals(merType)){
							resultMap.put("msg", "第"+checkDataCount+"行商户类型值填写错误");
							return false;
						}
						
						//商户直间连
						String merzjCont = Constance.Null2EmptyTrim(obj.get(DIRECT_IND));
						if(!"0".equals(merzjCont) && !"1".equals(merzjCont)){
							resultMap.put("msg", "第"+checkDataCount+"行商户直间连值填写错误，只能导入间联和直联商户");
							return false;
						}
						
						//特殊计费类型
						String specialFeeType = Constance.Null2EmptyTrim(obj.get(SPECIAL_FEE_TYPE_IND));
						//特殊计费档次
						String specialFeeLevel = Constance.Null2EmptyTrim(obj.get(SPECIAL_FEE_LEVEL_IND));
						if("".equals(specialFeeType) && "".equals(specialFeeLevel)){
							obj.set(SPECIAL_FEE_TYPE_IND, "00");
							obj.set(SPECIAL_FEE_LEVEL_IND, "000");
						}else if("".equals(specialFeeType) ^ "".equals(specialFeeLevel)){
							resultMap.put("msg", "第"+checkDataCount+"特殊计费类型和特殊计费档次填写不完整");
							return false;
						}
						
						//结算账户类型  '0':'私人账户','1':'企业账户' 
						String bankAccountType = Constance.Null2EmptyTrim(obj.get(ACCOUNT_TYPE_IND));
						if(!"0".equals(bankAccountType) && !"1".equals(bankAccountType)){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户类型填写错误");
							return false;
						}
						
						//结算账户名称
						String bankAccountName = Constance.Null2EmptyTrim(obj.get(ACCOUNT_NAME_IND));
						if("".equals(bankAccountName)){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户名称为空");
							return false;
						}
						
						if(bankAccountName.length()>26){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户名称长度过长");
							return false;
						}
						
						
						
						//若为企业账户
						if("1".equals(bankAccountType)){
							/*if(!certif.equals(bankAccountName)){
								resultMap.put("msg", "第"+checkDataCount+"行企业账户结算账户名称必须与法人代表相同");
								return false;
							}*/
							obj.set(IS_CERTIF_IND, "");
							obj.set(NO_CERTIF_IND, "");
						}
						
						//若为私人账户
						if("0".equals(bankAccountType)){
							//是否法人结算
							String isCertifSettle = Constance.Null2EmptyTrim(obj.get(IS_CERTIF_IND));
							//非法人身份证号
							String notCertifNo = Constance.Null2EmptyTrim(obj.get(NO_CERTIF_IND));
							
							if(!"0".equals(isCertifSettle) && !"1".equals(isCertifSettle)){
								resultMap.put("msg", "第"+checkDataCount+"行是否法人结算填写错误");
								return false;
							}
							
							if("0".equals(isCertifSettle)){//是
								if(!certif.equals(bankAccountName)){
									resultMap.put("msg", "第"+checkDataCount+"行私人账户是法人结算时结算账户名称必须与法人代表相同");
									return false;
								}
								obj.set(NO_CERTIF_IND, "");
							}
							
							if("1".equals(isCertifSettle)){//非法人结算
								if("".equals(notCertifNo) || !isIdCard(notCertifNo)){
									resultMap.put("msg", "第"+checkDataCount+"行非法人身份证号填写错误");
									return false;
								}
							}
							
						}
						
						//结算账户账号
						String bankAccoutn = Constance.Null2EmptyTrim(obj.get(ACCOUNT_IND));
						if("".equals(bankAccoutn)){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户账号为空");
							return false;
						}
						if(bankAccoutn.length()>40){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户账号长度过大");
							return false;
						}
						
						
						
						//开户行名称
						String bankName = Constance.Null2EmptyTrim(obj.get(BANK_NAME_IND));
						if("".equals(bankName)){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户开户行名称为空");
							return false;
						}
						
						if(bankName.length()>66){
							resultMap.put("msg", "第"+checkDataCount+"行结算账户开户行名称长度过大");
							return false;
						}
						
						//是否特殊费率商户 0-否  1-是
						String isSpecialFee = Constance.Null2EmptyTrim(obj.get(IS_SPECIAL_FEE_IND));
						if(!"0".equals(isSpecialFee) && !"1".equals(isSpecialFee)){
							resultMap.put("msg", "第"+checkDataCount+"行是否特殊费率商户列值填写错误");
							return false;
						}
						
						if("0".equals(isSpecialFee)){//非特殊费率商户
							String s2 = Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND));// T1  1000
							String s3 = Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND));// T0  1171
							// T0不能单独存在
							if (!"1000".equals(s2)) {// T1 没值或者值错误
								resultMap.put("msg", "第"+checkDataCount+"行开通T1值必须为1000");
								return false;
							} else {
								if ("1000".equals(s2)) {// T1
									String s4 = Constance.Null2EmptyTrim(obj
											.get(T1_JIE_FEE_IND));
									String s5 = Constance.Null2EmptyTrim(obj
											.get(T1_JIE_MAX_IND));
									String s6 = Constance.Null2EmptyTrim(obj
											.get(T1_DAI_FEE_IND));
									if ("".equals(s4) || "".equals(s5)
											|| "".equals(s6)) {
										resultMap.put("msg", "第"+checkDataCount+"行T1的封顶或者费率为空");
										return false;
									} else {
										if(!isNumber(s4)||!isNumber(s5)||!isNumber(s6)){
											resultMap.put("msg", "第"+checkDataCount+"行T1的封顶或者费率填写不规范");
											return false;
										}
										
										if (new BigDecimal(s4).doubleValue() < 0.5) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的借记卡费率不能小于百分之0.5");
											return false;
										}
										if (new BigDecimal(s5).doubleValue() < 20) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的借记卡封顶不能低于20");
											return false;
										}

										if (new BigDecimal(s6).doubleValue() < 0.55) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的贷记卡费率不能小于百分之0.55");
											return false;
										}

									}
								}

								if ("1171".equals(s3)) {// T0
									String s7 = Constance.Null2EmptyTrim(obj
											.get(T0_JIE_FEE_IND));
									String s8 = Constance.Null2EmptyTrim(obj
											.get(T0_DAI_FEE_IND));
									if ("".equals(s7) || "".equals(s8)) {
										resultMap.put("msg", "第"+checkDataCount+"行T0借记卡或者贷记卡费率不能为空");
										return false;
									} else {
										
										if(!isNumber(s7)||!isNumber(s8)){
											resultMap.put("msg", "第"+checkDataCount+"行T0费率填写不规范");
											return false;
										}
										
										if (new BigDecimal(s7).doubleValue() < 0.55) {
											resultMap.put("msg", "第"+checkDataCount+"行T0借记卡费率不能小于百分之0.55");
											return false;
										}
										if (new BigDecimal(s8).doubleValue() < 0.55) {
											resultMap.put("msg", "第"+checkDataCount+"行T0贷记卡费率不能小于百分之0.55");
											return false;
										}
									}
								}else if(!"".equals(s3) && !"1171".equals(s3)){
									resultMap.put("msg", "第"+checkDataCount+"行开通T0必须为1171");
									return false;
								}
							}
						}else{//特殊费率商户
							
							String s2 = Constance.Null2EmptyTrim(obj.get(OPEN_T1_IND));// T1  1000
							String s3 = Constance.Null2EmptyTrim(obj.get(OPEN_T0_IND));// T0  1171
							// T0不能单独存在
							if (!"1000".equals(s2)) {// T1 没值或者值错误
								resultMap.put("msg", "第"+checkDataCount+"行开通T1值必须为1000");
								return false;
							} else {
								if ("1000".equals(s2)) {// T1
									String s4 = Constance.Null2EmptyTrim(obj
											.get(T1_JIE_FEE_IND));
									String s5 = Constance.Null2EmptyTrim(obj
											.get(T1_JIE_MAX_IND));
									String s6 = Constance.Null2EmptyTrim(obj
											.get(T1_DAI_FEE_IND));
									if ("".equals(s4) || "".equals(s5)
											|| "".equals(s6)) {
										resultMap.put("msg", "第"+checkDataCount+"行T1的封顶或者费率为空");
										return false;
									} else {
										if(!isNumber(s4)||!isNumber(s5)||!isNumber(s6)){
											resultMap.put("msg", "第"+checkDataCount+"行T1的封顶或者费率填写不规范");
											return false;
										}
										
										if (new BigDecimal(s4).doubleValue() < 0) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的借记卡费率不能小于0");
											return false;
										}
										if (new BigDecimal(s5).doubleValue() < 0) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的借记卡封顶不能低于0");
											return false;
										}

										if (new BigDecimal(s6).doubleValue() < 0) {
											resultMap.put("msg", "第"+checkDataCount+"行T1的贷记卡费率不能小于0");
											return false;
										}
										
										
									}
								}

								if ("1171".equals(s3)) {// T0
									String s7 = Constance.Null2EmptyTrim(obj
											.get(T0_JIE_FEE_IND));
									String s8 = Constance.Null2EmptyTrim(obj
											.get(T0_DAI_FEE_IND));
									if ("".equals(s7) || "".equals(s8)) {
										resultMap.put("msg", "第"+checkDataCount+"行T0借记卡或者贷记卡费率不能为空");
										return false;
									} else {
										
										if(!isNumber(s7)||!isNumber(s8)){
											resultMap.put("msg", "第"+checkDataCount+"行T0费率填写不规范");
											return false;
										}
										
										if (new BigDecimal(s7).doubleValue() < 0) {
											resultMap.put("msg", "第"+checkDataCount+"行T0借记卡费率不能小于0");
											return false;
										}
										if (new BigDecimal(s8).doubleValue() < 0) {
											resultMap.put("msg", "第"+checkDataCount+"行T0贷记卡费率不能小于0");
											return false;
										}
										
									}
								}else if(!"".equals(s3) && !"1171".equals(s3)){
									resultMap.put("msg", "第"+checkDataCount+"行开通T0必须为1171");
									return false;
								}
							}
						
						}
						
						String balanceQuery = Constance.Null2EmptyTrim(obj.get(BALANCE_QUERY_IND));
						if(!"".equals(balanceQuery) && !"1001".equals(balanceQuery)){
							resultMap.put("msg", "第"+checkDataCount+"行余额查询值填写错误");
							return false;
						}
						
						String reverse  = Constance.Null2EmptyTrim(obj.get(REVERSE_IND));
						if(!"".equals(reverse) && !"2011".equals(reverse)){
							resultMap.put("msg", "第"+checkDataCount+"行消费撤销值填写错误");
							return false;
						}
						
						String cz = Constance.Null2EmptyTrim(obj.get(CZ_IND));
						if(!"".equals(cz) && !"4011".equals(cz)){
							resultMap.put("msg", "第"+checkDataCount+"行消费冲正值填写错误");
							return false;
						}
						
						
						//开通终端数
						String s1 = Constance.Null2EmptyTrim(obj.get(OPEN_TERM_IND));
						if ("".equals(s1)) {
							resultMap.put("msg", "第"+checkDataCount+"行开通终端数为空");
							return false;
						}
						
						if(!isPositiveInteger(s1)){
							resultMap.put("msg", "第"+checkDataCount+"行开通终端数填写不规范");
							return false;
						}
						
						
						//终端数要和安装地址数量一致，并且终端数量不能超过10
						
						int snNum = Integer.parseInt(s1);
						int addrNum = obj.size() - ALL_COLUMN;
						int realSnNum = 0;
						for(int i=0;i<addrNum;i++){
							String realSn = Constance.Null2EmptyTrim(obj.get(ALL_COLUMN+i));
							if(!"".equals(realSn)){
								realSnNum++;
							}
						}
						if (snNum <= 0 || snNum >= 11 || snNum != realSnNum) {
							resultMap.put("msg", "第"+checkDataCount+"行开通终端数不能大于10或者开通终端数目与终端地址数目不相符");
							return false;
						}
						
						//终端品牌
						Map<String, String> brandMap = ConfigProperties.getSysDB1("TMNL_BRAND",true);
						
						
						for(int i = 0;i<snNum;i++){
							String realSnIsNotNull = Constance.Null2EmptyTrim(obj.get(ALL_COLUMN+i));
							
							if("".equals(realSnIsNotNull)){
								resultMap.put("msg", "第"+checkDataCount+"行的终端信息请按顺序填写，不要留有空格");
								return false;
							}
							
							String[] termMsgArray = realSnIsNotNull.split(",");
							int len = termMsgArray.length;
							
							if(len != 1 && len != 2 && len != 5){
								resultMap.put("msg", "第"+checkDataCount+"行终端信息填写格式有误");
								return false;
							}
							
							for(int j = 0;j<len;j++){
								if(len == 1){//装机地址
									String insLoc = Constance.Null2EmptyTrim(termMsgArray[0]);
									if("".equals(insLoc) || insLoc.length()>33){
										resultMap.put("msg", "第"+checkDataCount+"行的装机地址为空或者长度过大");
										return false;
									}
								}else if(len == 2){//终端号,装机地址
									String termId = Constance.Null2EmptyTrim(termMsgArray[0]);
									String insLoc = Constance.Null2EmptyTrim(termMsgArray[1]);
									if("".equals(termId) || termId.length() != 8){
										resultMap.put("msg", "第"+checkDataCount+"行的终端号不能为空并且终端号长度必须为8");
										return false;
									}
									if("".equals(insLoc) || insLoc.length()>33){
										resultMap.put("msg", "第"+checkDataCount+"行的装机地址为空或者长度过大");
										return false;
									}
								}else{//终端号，sn，品牌，型号,装机地址
									String termId = Constance.Null2EmptyTrim(termMsgArray[0]);
									String sn = Constance.Null2EmptyTrim(termMsgArray[1]);
									String brand = Constance.Null2EmptyTrim(termMsgArray[2]);
									String model = Constance.Null2EmptyTrim(termMsgArray[3]);
									String insLoc = Constance.Null2EmptyTrim(termMsgArray[4]);
									if("".equals(termId) || termId.length() != 8){
										resultMap.put("msg", "第"+checkDataCount+"行的终端号不能为空并且终端号长度必须为8");
										return false;
									}
									
									if("".equals(sn)){
										resultMap.put("msg", "第"+checkDataCount+"行的终端序列号不能为空");
										return false;
									}
									
									
									
									boolean brandFlag = false;
									for(Entry<String, String> en: brandMap.entrySet()){
										if(brand.equals(en.getKey())){
											brandFlag =true;
										}
									}
									
									if(!brandFlag){
										resultMap.put("msg", "第"+checkDataCount+"行的终端品牌【"+brand+"】不存在");
										return false;
									}
									
									//终端型号
									Map<String, String> typeMap = ConfigProperties.getSyspostype("TMNL_MODEL_NO",brand,false);
									
									boolean typeFlag = false;
									for(Entry<String, String> en:typeMap.entrySet()){
										if(model.equals(en.getKey())){
											typeFlag = true;
										}
									}
									
									if(!typeFlag){
										resultMap.put("msg", "第"+checkDataCount+"行的终端型号【"+model+"】不存在");
										return false;
									}
									
									if("".equals(insLoc) || insLoc.length()>33){
										resultMap.put("msg", "第"+checkDataCount+"行的装机地址为空或者长度过大");
										return false;
									}
								}
							}
							
							
							
						}
						
					}else{
						resultMap.put("msg", "Excel记录格式不正确");
						return false;
					}//判断每一条记录的规则  结束
					checkDataCount ++;
				}
			}else{
				resultMap.put("msg", "Excel中没有任何记录");
				return false;
			}
		} catch (Exception e) {
			log.error("商户批量导入数据校验异常:" + e.getMessage());
			resultMap.put("msg", "商户批量导入数据校验异常:" + e.getMessage());
			return false;
			
		}
		return true;

	}

	
	public boolean transCodeByName(Map<String,String> modelMap,String desValue,int index,List<Object> objList){
		boolean flag = false;
		Set<Entry<String,String>> entrySet = modelMap.entrySet();
		Iterator<Entry<String,String>> entryIter = entrySet.iterator();
		while(entryIter.hasNext()){
			Entry<String,String> en = entryIter.next();
			if(desValue.equals(en.getValue())){
				objList.set(index, en.getKey());
				flag =true;
				break;
			}
		}
		return flag;
	}
	
	/******************************以下校验皆未校验非空**************************/
	/**
	 * 正则表达式判断数字
	 * @param regextStr
	 * @param des
	 * @return
	 */
	public static boolean isNumber(String des){
		String regextStr = "[-|\\+]{0,1}\\d+[\\.]?\\d*|[-|\\+]{0,1}\\d*\\.\\d+";
		 Pattern pattern = Pattern.compile(regextStr);  
	     Matcher isNum = pattern.matcher(des);  
		return isNum.matches();
	}
	
	/**
	 * 判断身份证号码
	 * @param str
	 * @return
	 * @throws Exception 
	 */
	public static boolean isIdCard(String str) throws Exception{
        boolean flag = CheckIdCard.iDCardValidate(str);
        return flag;
    }
	
	/**
	 * 手机号码校验
	 * @param str
	 * @return
	 */
	public static boolean isPhNumber(String str){
		if(str.length() != 11){
			return false;
		}
		return true;
	}
	
	public static boolean isPositiveInteger(String str){
		String regextStr = "[0-9]*[1-9][0-9]*";
		 Pattern pattern = Pattern.compile(regextStr);  
	     Matcher isNum = pattern.matcher(str);  
		return isNum.matches();
	}
	
	/**
	 * 判断时间是否符合格式
	 * @param dateStr
	 * @return
	 */
	public static boolean isRegularTime(String dateStr,String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = null;
		try {
			
			date = sdf.parse(dateStr);
		} catch (ParseException e) {
			return false;
		}
		String ds = sdf.format(date);
		return ds.equals(dateStr);
	}
	
	/**
	 * 由于数据库同步只有五分钟,批导时间过长导致超出同步时间范围
	 * @return
	 */
	public static Date obtainSomeLaterTime(){
		Calendar nowTime = Calendar.getInstance();
		nowTime.add(Calendar.MINUTE, 10);
		return nowTime.getTime();
		
	}
	
	public static void main(String[] args) {
//		System.out.println(excelToList(new File("D:/excel/2.xlsx"), null));
//		System.out.println(isPositiveInteger("5.0"));
//		System.out.println(isRegularTime("2324"));
		/*String[] modelTitleArray = {"机构号","商户号","装机地址市/县","MCC42域","商户工商注册名称","营业名称",
				"营业执照号码","经营范围","主营业务","法人代表","法人证件类型","法人代表证件号","身份证有效期","商户联系人电话","营业起始时间",
				"营业终止时间","商户注册地址省地址","商户注册地址地市地址","商户注册地址区县地址","商户注册地址","商户类型","商户直间连","特殊计费类型",
				"特殊计费档次","结算账户类型","是否法人结算","非法人身份证号","结算账户名称","结算账户账号","结算账户开户行名称","是否特殊费率商户",
				"开通T1","T1借记卡费率(%)","T1借记卡封顶","T1贷记卡费率(%)","开通T0","T0借记卡费率(%)","T0贷记卡费率(%)","余额查询",
				"消费撤销","开通终端数量"};
		
		System.out.println(modelTitleArray.length);*/
		
		/*String str = " , , ";
		System.out.println(str.split(",").length);*/
		try {
			throw new RuntimeException("运行时异常");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	

}
